<?php
// +----------------------------------------------------------------------
// | Created by Sublime: [ Conqweal ]
// +----------------------------------------------------------------------
// | Copyright (c) 2021~20223[chenjia] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.99dn.cn
// +----------------------------------------------------------------------
// | Author: Conqweal <150672834@qq.com>
// +----------------------------------------------------------------------
// | Date: 2021/12/22 0026
// +----------------------------------------------------------------------
// | Description:任务配置
// +----------------------------------------------------------------------


namespace app\admin\controller;
use app\BackendController;
use app\admin\model\UserCredit as credit;
use think\facade\Cache;
use support\Request;
use think\facade\Db;

class MissionSetController extends BackendController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $cfg        = getConfig("mission");
        $credit     = credit::creditBasic();
        $creditdata = getConfig("credit");
        $paypal = getConfig("paypal");
        if ($creditdata) {
            array_walk($credit, function (&$v, $k) use ($creditdata) {
                $v[1] = $creditdata[$k];
            });

        }
        return view('missionset/index', compact('cfg', 'credit','paypal'));

    }

    /**



    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request)
    {
        $config               = new \app\admin\model\Config();
        $config->option_name  = "mission";
        $config->option_value = $request->post();
        $config->replace()->save();
        \think\facade\Cache::delete("configs");
        return json(['status' => 1, 'msg' => "保存成功"]);
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function updateCredit(Request $request)
    {
        $config               = new \app\admin\model\Config();
        $config->option_name  = "credit";
        $config->option_value = $request->post();
        $config->replace()->save();
        \think\facade\Cache::delete("configs");
        return json(['status' => 1, 'msg' => "保存成功"]);
    }

    /**
     * 保存更新paypal
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function updatePaypal(Request $request)
    {
        $config               = new \app\admin\model\Config();
        $config->option_name  = "paypal";
        $config->option_value = $request->post();
        $config->replace()->save();
        \think\facade\Cache::delete("configs");
        return json(['status' => 1, 'msg' => "保存成功"]);
    }

}
